package com.sunday.factory.singletonDemo;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @ClassName StaticSingleton
 * @Author JiangHai
 * @Date 2021/9/5 14:35
 **/
public class StaticSingleton {

    private AtomicLong id = new AtomicLong(0);

    private StaticSingleton(){
        // 禁止通过反射创建对象
        throw new IllegalArgumentException();
    }

    public static class SingletonHolder {
        private static final StaticSingleton instance = new StaticSingleton();
    }

    public long getId() {
        return id.incrementAndGet();
    }
}
